using Godot;
using System;

public partial class Monster : Sprite2D
{
    float HP = 400; // 怪物血量

    // Called when the node enters the scene tree for the first time.
    public override void _Ready()
    {
        var area = this.GetNode<Area2D>("Area2D");
        area.Connect("area_entered", new Callable(this, nameof(onCollisionEnter)));
    }

  public void onCollisionEnter(Area2D area)
{
    HP -= 1; // 每次碰撞减少 1 点血量
    GD.Print("怪物被碰撞了！当前血量：" + HP);

    if (HP <= 0)
    {
        GD.Print("怪物死亡！");
        this.QueueFree(); // 销毁怪物节点
    }
}

    // Called every frame. 'delta' is the elapsed time since the previous frame.
    public override void _Process(double delta)
    {
    }
}